// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import ComponentBase from "../BASE/ComponentBase";
import turn from "../game/time/turn";
import { Message } from "../Message/Message";
import MessageCenter from "../Message/MessageCenter";
import { SHMessage } from "../Message/SHMessage";
import GeZiManager from "./GeZiManager";



const {ccclass, property} = cc._decorator;

@ccclass
export default class TNanager extends ComponentBase {





 onLoad() {
  turn.Roo.push(this)
  MessageCenter.addReceive(this)
  
    }



   
 roundPass(): void {


if(turn.round>=2){
    
      switch (GeZiManager.TNJM[turn.round%12-1]) {
        case 2:GeZiManager.TNC=[1,1,3,4,4,2]//移动
            
            break;
            case 1:GeZiManager.TNC=[1,3,1,4,4,2]//蓄气
            
            break;
            case 0:GeZiManager.TNC=[1,3,3,2,4,2]//攻击
            
            break;
            case 7:GeZiManager.TNC=[1,3,3,4,2,2]//法术
            
            break;
            case 3:GeZiManager.TNC=[1,3,3,4,4,0]//商店        
            break;
     
        case 5:GeZiManager.TNC=[0,3,3,4,4,2]//转身
        break;
        case 6:GeZiManager.TNC=[1,3,3,6,4,2]//转身
        break;
        default:GeZiManager.TNC=[1,3,3,4,4,2]//转身
    break


 }   
// this.lun.string=GeZiManager.TNC+""
}
}
static makePool(): number[][] {
  const pools: number[][] = [];
  for (let j = 0; j < 3; j++) {
    const validNumbers = [0, 1, 2, 3, 5, 7]; // 可选数字集合，只包含0和1
    const arr = [1]; // 第二个数字是2
    let lastNumber = 2; // 上一个数字是2
    let twoCount = 1; // 统计出现的2的个数
    let oneCount = 0; // 统计出现的1的个数
    for (let i = 1; i < 12; i++) {
      const candidates = validNumbers.filter(n => n !== lastNumber); // 候选数字集合不能与上一个数字相同
      if (twoCount < 2&&i>3) {
        candidates.push(2); // 如果已经有不足3个2，则候选数字集合中添加2
      }
      if (oneCount < 2&&i>4) {
        candidates.push(3); // 如果已经有不足4个1，则候选数字集合中添加1
      }
      const numberIndex = Math.floor(Math.random() * candidates.length); // 随机选取一个数字
      const number = candidates[numberIndex];
      arr.push(number);
      lastNumber = number;
      if (number === 1) {
        oneCount++;
      } else {
        oneCount = 0;
      }
      if (number === 2) {
        twoCount++;
      } else {
        twoCount = 0;
      }
    }
    arr[3]=6;
    arr[6]=6;
    arr[10]=6;
    pools.push(arr);
  }
  const mergedArray = [].concat(...pools);
  console.log(mergedArray); // 打印合并后的一维数组
  return mergedArray;
}
      

TN(){
  if(turn.round>0){
    switch (GeZiManager.TNJM[turn.round-1]) {
    case 2:GeZiManager.TNC=[1,1,3,4,4,2]//移动
        
        break;
        case 1:GeZiManager.TNC=[1,3,1,4,4,2]//蓄气
        
        break;
        case 0:GeZiManager.TNC=[1,3,3,2,4,2]//攻击
        
        break;
        case 7:GeZiManager.TNC=[1,3,3,4,2,2]//法术
        
        break;
        case 3:GeZiManager.TNC=[1,3,3,4,4,0]//商店        
        break;
 
    case 5:GeZiManager.TNC=[0,3,3,4,4,2]//转身
    break;
    case 6:GeZiManager.TNC=[1,3,3,6,4,2]//转身
    break;
    default:GeZiManager.TNC=[1,3,3,4,4,2]//转身
break
 }   
 console.log(GeZiManager.TNJM[turn.round%12]+"")
 console.log(GeZiManager.TNC+"")
 //this.lun.string=GeZiManager.TNC+""
}

}

ReceiveMessage(message: Message): void {
   
    if (message instanceof SHMessage&&message.Type=="TN") {
        console.log(message.Command)
        switch (message.SHtype) {
            case "pool":GeZiManager.TNJM=[].concat(message.Command); 
//cc.find("Canvas/DituManager/New Node/nodecol/xgcol").getComponent(xgcol).c();

                break;}}}
}
